package service.member;

import vo.MemberVO;
import dao.member.MemberDAO;

public class MemberServiceImpl implements MemberService{
	
	private MemberDAO memberDAO;

	public void setMemberDAO(MemberDAO memberDAO) {
		this.memberDAO = memberDAO;
	}

	@Override
	public int login(String member_mail, String member_pass) throws Exception {
		MemberVO mvo=memberDAO.login(member_mail);
		int member_no=0;
		if(mvo==null){
			member_no=-2;
		}else{
			boolean loginOk=mvo.getMember_pass().equals(member_pass);
			if(loginOk){
				member_no=mvo.getMember_no();
			}else{
				member_no=-1;
			}
		}
		return member_no;
	}

	@Override
	public int registerMember(String member_mail, String member_pass)
			throws Exception {
		if(memberDAO.isMember(member_mail)==0){
			return memberDAO.registerMember(new MemberVO(member_mail, member_pass));
		}else{
			return -1;
		}
	}

	@Override
	public int findPass(String member_mail) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean updatePass(int member_no, String member_pass) throws Exception {
		int result=memberDAO.updatePass(new MemberVO(member_no, member_pass));
		if(result<=0) return false;
		return true;
	}

	@Override
	public void deleteMember(int member_no) throws Exception {
		memberDAO.deleteMember(member_no);
	}
}